<cfparam default="0" name="url.action">
<cfcontent reset="yes">
<cfset querypass = ''>
<cfset querypass = 'WHERE '>

<cfset querypass = querypass & "1 =0">


<cfinvoke component="components.data" method="search_poc" returnvariable="search_results" paramvar="#querypass#">


<cfswitch expression="#url.action#">

<cfcase value="get_first">

<cfset lowest_limit = 1>
<cfset highest_limit = 10>

</cfcase>

<cfcase value="get_previous">

<cfset highest_limit = lowest_term - 1>
<cfset lowest_limit = highest_limit - 9>
<cfif lowest_limit LT 1>
	<cfset lowest_limit = 1>
	<cfset highest_limit = 10>
</cfif>

</cfcase>

<cfcase value="get_next">

<cfset lowest_limit = highest_term + 1>
<cfset highest_limit = lowest_limit + 9>
<cfif highest_limit GT search_results.RecordCount>
	<cfset lowest_limit = search_results.RecordCount - 9>
	<cfset highest_limit = search_results.RecordCount>
</cfif>

</cfcase>

<cfcase value="get_last">

<cfset lowest_limit = search_results.RecordCount - 9>
<cfset highest_limit = search_results.RecordCount>

</cfcase>

</cfswitch>

<cfif search_results.RecordCount NEQ 0>
	<cfset lowest_result = search_results.RecordCount>
	<cfset highest_result = 1>
	<cfset result_message = ''>
	<cfset result_message = '{"result":['>
	<cfloop query="search_results">
		<cfif search_results.CurrentRow GTE lowest_limit AND search_results.CurrentRow LTE highest_limit>		
		
			<cfset result_message =  result_message & '{"poc_id":"' & search_results.poc_id & '","first_name":"' & Session.helpers.add_json_escapement(search_results.first_name) & '","last_name":"'>
			<cfset result_message = result_message & Session.helpers.add_json_escapement(search_results.last_name)>			
			<cfset result_message =  result_message & '","email":"'>		
			<cfset result_message = result_message & Session.helpers.add_json_escapement(search_results.email)>
	
						
			<cfset result_message = result_message & '"},'>
			<cfif search_results.CurrentRow LT lowest_result>
				<cfset lowest_result = search_results.CurrentRow>
			</cfif>
			<cfif search_results.CurrentRow GT highest_result>
				<cfset highest_result = search_results.CurrentRow>
			</cfif>
		</cfif>
	</cfloop>
	<cfset result_message = Session.helpers.remove_comma_from_end_of_string(result_message)>
	<cfset result_message = result_message & '],'>
	<cfset result_message = result_message & '"search_info":[{"lowest":"' & lowest_result & '","highest":"' & highest_result & '","search_term":"' & '","count":"' & search_results.RecordCount & '"}]}'>
	<cfcontent type="text/html" reset="yes"><cfoutput>#result_message#</cfoutput>
<cfelse>
</cfif>